package com.github.niefy.modules.wx.controller;

import com.github.niefy.common.utils.PageUtils;
import com.github.niefy.common.utils.R;
import com.github.niefy.modules.wx.service.WxAssetsService;
import com.github.niefy.modules.wx.service.WxPublicationRecordsService;
import com.github.niefy.modules.wx.service.WxTemplateLogService;
import com.github.niefy.modules.wx.service.WxUserService;
import com.thoughtworks.xstream.mapper.Mapper;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.freepublish.WxMpFreePublishArticles;
import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 文章管理
 */
@RestController
@RequestMapping("/WxPub")
@RequiredArgsConstructor
@Api(tags = {"文章管理"})
public class WxPublicationRecordsController {

    @Autowired
    private WxPublicationRecordsService wxPublicationRecordsService;

    @Autowired
    WxAssetsService wxAssetsService;

    private final WxMpService wxMpService;

    /**
     * 列表
     */
    @RequestMapping("/syncWxArticle")
//    @RequiresPermissions("wx:WxPub:getPublish")
    public R syncWxArticle(@CookieValue String appid) throws WxErrorException {
        this.wxMpService.switchoverTo(appid);
        return R.ok().put("page", wxPublicationRecordsService.syncWxArticle(appid));
    }

    /**
     * 列表
     */
    @RequestMapping("/getPublish")
//    @RequiresPermissions("wx:WxPub:getPublish")
    public R getPublish(@CookieValue String appid,int page) throws WxErrorException {
        this.wxMpService.switchoverTo(appid);
        return R.ok().put("page", wxPublicationRecordsService.getPublish(appid,page));
    }

    /**
     * 列表
     */
    @RequestMapping("/getThumb")
//    @RequiresPermissions("wx:WxPub:getPublish")
    public R getThumb(@CookieValue String appid,String mediaId) throws WxErrorException {
        return R.ok().put("page", wxPublicationRecordsService.getThumb(appid,mediaId));
    }

}
